#include "DAGraphicsResizeableTextItem.h"
#include <QDebug>
#include <QFont>
#include <QPainter>
#include <QTextItem>
using namespace DA;
DAGraphicsResizeableTextItem::DAGraphicsResizeableTextItem(QGraphicsItem* parent)
    : DAGraphicsResizeableItem(parent), m_textItem(nullptr)
{
    m_textItem = new QGraphicsTextItem();
    m_textItem->setPlainText("QGraphicsTextItem");
    m_textItem->setFont(QFont("华文琥珀", 12));
    m_textItem->setDefaultTextColor(Qt::green);  //设置字体颜色
    m_textItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
}

void DAGraphicsResizeableTextItem::setBodySize(const QSizeF& s)
{
}

void DAGraphicsResizeableTextItem::paintBody(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget, const QRectF& bodyRect)
{
    qDebug() << "paintBody";
    Q_UNUSED(widget);
    painter->setRenderHint(QPainter::SmoothPixmapTransform);
    painter->setFont(QFont("华文琥珀", 15));
    painter->setPen(QColor(Qt::green));
    QString text = "QGraphicsTextItem";
    painter->drawText(bodyRect.center(), text);
    painter->restore();
    //    if (!d_ptr->_renderer->isValid()) {
    //        return;
    //    }

    //    if (d_ptr->_elemId.isEmpty()) {
    //        d_ptr->_renderer->render(painter, d_ptr->_svgPaintRect);
    //    } else {
    //        d_ptr->_renderer->render(painter, d_ptr->_elemId, d_ptr->_svgPaintRect);
    //    }
}
